
/**
 * 选择客户
 */
import { Select } from "@/components/base";
import React from "react";
import * as apis from "@/apis";

export interface ISelectClientProps {

    /** 用户数据改变 */
    onChange?: (value: string) => void;

    /** 客户全称 */
    value?: string;

    /** 是否禁用 */
    disabled?: boolean
}

export function SelectClient(props: ISelectClientProps) {

    const [clientList, setClientList] = React.useState<any[]>([]);

    React.useEffect(() => {
        apis.client.list.post({ pagination: { page: 1, pageSize: 9999 } })
            .then(res => {
                setClientList(res.list);
            });
    }, [])

    return (
        <Select
            showSearch
            allowClear
            disabled={props.disabled}
            value={props.value}
            onChange={props.onChange}
            fieldNames={{ label: 'clientName', value: 'id' }}
            filterOption={(input, option: any) => option.clientName.indexOf(input) >= 0}
            options={clientList}
        />
    )
}